﻿using exMath.Statistics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace exMath.Test
{
    
    
    /// <summary>
    ///This is a test class for BasicStatisticsTest and is intended
    ///to contain all BasicStatisticsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class BasicStatisticsTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for PercentageFromAmount
        ///</summary>
        [TestMethod()]
        public void PercentageFromAmountTest()
        {
            double MaxAmount = 200.0;
            double ActualAmount = 50.0;
            double expected = 25.0; 
            double actual;
            actual = BasicStatistics.PercentageFromAmount(MaxAmount, ActualAmount);
            Assert.AreEqual(expected, actual);

        }

        /// <summary>
        ///A test for AmountFromPercentage
        ///</summary>
        [TestMethod()]
        public void AmountFromPercentageTest()
        {
            double MaxAmount = 200.0; 
            double Percentage = 25.0; 
            double expected = 50.0; 
            double actual;
            actual = BasicStatistics.AmountFromPercentage(MaxAmount, Percentage);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Mean
        ///</summary>
        [TestMethod()]
        public void MeanTest()
        {
            double[] Values = { 2.0, 2.0, 4.0, 4.0 }; 
            double expected = 3.0; 
            double actual;
            actual = BasicStatistics.Mean(Values);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Min
        ///</summary>
        [TestMethod()]
        public void MinTest()
        {
            double[] Values = { 2.0, 1.3, 1.2, 2.1, 1.5, 1.7 };
            double expected = 1.2; 
            double actual;
            actual = BasicStatistics.Min(Values);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Max
        ///</summary>
        [TestMethod()]
        public void MaxTest()
        {
            double[] Values = { 1.0, 2.0, 1.3, 1.2, 2.1, 1.5, 1.7 };
            double expected = 2.1; 
            double actual;
            actual = BasicStatistics.Max(Values);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Mode
        ///</summary>
        [TestMethod()]
        public void ModeTest()
        {
            double[] Values = { 1.0, 2.0, 2.0, 3.0, 4.1, 4.1, 4.1, 5.0, 6.0, 9.0, 9.0 }; 
            double expected = 4.1;
            double actual;
            actual = BasicStatistics.Mode(Values);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for StandardDeviation
        ///</summary>
        [TestMethod()]
        public void StandardDeviationTest()
        {
            double[] values = { 1.0, 2.0, 3.0 };
            double stdDeviation = BasicStatistics.StandardDeviation(values);

            Assert.AreEqual(1.0, stdDeviation);
        }

        /// <summary>
        ///A test for PopulationVariance
        ///</summary>
        [TestMethod()]
        public void VarianceTest()
        {
            double[] values = { 1.0, 2.0, 3.0 };
            double variance = BasicStatistics.Variance(values);

            Assert.AreEqual(1.0, variance);
        }

        /// <summary>
        ///A test for Correlation
        ///</summary>
        [TestMethod()]
        public void CorrelationTest()
        {
            double[] DomainValues = { 1.0, 2.0, 3.0 };
            double[] RangeValues = { 1.0, 2.0, 3.0 };

            double Correlation = BasicStatistics.Correlation(DomainValues, RangeValues);
            Assert.AreEqual(1.0, Correlation);

            double[] DomainValues2 = { 1.0, 2.0, 3.0 };
            double[] RangeValues2 = { 1.0, 1.0, 1.0 };

            double Correlation2 = BasicStatistics.Correlation(DomainValues2, RangeValues2);
            Assert.AreEqual(0.0, Correlation2);
        }
    }
}
